package com.shawny.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration;
import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler;
import org.springframework.web.socket.server.support.AbstractHandshakeHandler;

/**
 * Created by Shawn Wong on 2017/3/30.
 * Try you best !
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketBrokerConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic", "/user");
        config.setApplicationDestinationPrefixes("/msg");
        config.setUserDestinationPrefix("/user/");
    }

    public void registerStompEndpoints(StompEndpointRegistry registry) {

        registry.addEndpoint("/webServer").setHandshakeHandler(new UUIDhandshakeHandler()).setAllowedOrigins("*").withSockJS();
    }


}
